//
//  SafeVC.swift
//  whale
//
//  Created by topnet on 2022/7/26.
//

import UIKit

final class SafeVC: ICBaseVC {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func _initUI() {
        super._initUI()
        navBar.titleV.text = "账号安全"
        
        listV.tableFooterView = logOutBtn
        view.addSubview(listV)
    }
    
    override func _initData() {
        let dataSource = [
            MeModel(footerHeight: 10.adapter,
                    rows: [
                HeadTailModel(title: "修改密码", vcType: ModifyPwdVC.self),
                HeadTailModel(title: "忘记密码", vcType: ForgetPwdVC.self)
            ]),
        ]
        listV.configData(data: dataSource, cellType: HeadTailCell.self) { [weak self] path, md, cell in
            
        } itemSelected: { [weak self] path, md in
            if let mod = md as? HeadTailModel {
                if let vcType = mod.vcType {
                    self?.push(type: vcType)
                }
            }
        }
    }
    
    private func actionLogOut() {
        AlertUtil.alert(title: "是否注销账号", isAutoDissMiss: true, rightHandler:  { [weak self] in
            self?.backUtil()
        })
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        listV.left_right(view).top(UIScreen.navH).bottom(view.bounds.height-view.safeAreaInsets.bottom)
    }
    
    private lazy var disposeBag = DisposeBag()
    
    lazy var listV: GroupedListView = {
        let v = GroupedListView(frame: .zero, style: .grouped)
        v.cellType = MeCell.self
        return v
    }()

    
    private lazy var logOutBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.backgroundColor = .selectedBackground
        btn.frame = CGRect(x: 0, y: 0, width: UIScreen.width, height: 50.adapter)
        btn.setTitle("注销", for: .normal)
        btn.setTitleColor(.title, for: .normal)
        btn.rx.tap.throttle(.milliseconds(800), scheduler: MainScheduler.instance).subscribe(onNext: { [weak self] in
            self?.actionLogOut()
        }).disposed(by: disposeBag)
        return btn
    }()

}
